package com.newmuis.open.codeeval.easy;

import java.io.File;
import java.io.IOException;

/**
 * CodeEval.com > Easy Challenges > File Size
 * 
 * Description:
 * 
 * Print the size of a file in bytes.
 * 
 * Input sample:
 * 
 * Path to a filename. e.g.
 * 
 * foo.txt
 * 
 * Output sample:
 * 
 * Print the size of the file in bytes.
 * e.g.
 * 
 * 55
 * 
 * @author Jonathan Newmuis (jon@newmuis.com)
 * @category easy
 * 
 */
public class filesize {
	/**
	 * @param args should contain only one CLI argument: the path to an input file which specifies
	 *            the input in the defined format.
	 * @throws IOException if there is a problem reading the given input file.
	 */
	public static void main(final String[] args) throws IOException {
		// Verify input argument length.
		if (args.length < 1) {
			throw new RuntimeException("Must specify input file path.");
		} else if (args.length > 1) {
			throw new RuntimeException("Illegal input arguments specified.");
		}

		// Get a handle on the file.
		final File file = new File(args[0]);

		// Verify it exists.
		if (!file.exists()) {
			throw new RuntimeException("Specified file does not exist.");
		}

		// Output its size to System.out.
		System.out.println(file.length());
	}
}
